/*
2021-8-9
https://www.acwing.com/problem/content/3801/
*/ 
#include<iostream>

using namespace std;
typedef long long ll;

int main()
{
    int T;
    cin>>T;
    while(T--)
    {
        int n;
        cin>>n;
        ll sum=10;
        while(n>=sum) sum*=10;
        int num=n%(sum/10);
        cout<<(ll)sum/10-num<<endl;
    }
    return 0;
}
